package com.power.sifa.correction.dao;

import com.power.sifa.correction.model.Cre_warning_detail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 预警信息违规详情 持久层(hibernate)
 */

public interface Cre_warning_detailDao extends JpaRepository<Cre_warning_detail, Serializable>, JpaSpecificationExecutor<Cre_warning_detail>, Repository<Cre_warning_detail, Serializable>, Cre_warning_detailDaoCustom<Cre_warning_detail, Serializable> {

    @Modifying
    @Transactional
    @Query("delete  from Cre_warning_detail s where  s.id in (:ids) ")
    void removeByIds(@Param("ids") List<Integer> ids);

    @Query("from Cre_warning_detail s where  s.warningid = :warningId ")
    List<Cre_warning_detail> findByWarningId(@Param("warningId") String warningId);

    /**
     * 根据预警id查询明细
     *
     * @param warnid
     * @return
     */
    @Query(value = "select a.*, to_char(b.rectime, 'yyyy-MM-dd HH24:MI:SS') as rectime, b.photo from cre_warning_detail a left join cre_record_ga b on a.gaid = b.id where a.warningid = :warnid order by b.rectime desc", nativeQuery = true)
    List<Map<String, Object>> queryListByWarnid(String warnid);
}
